package com.intct.hbase.ddl.namesapce;

import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;

/**
 * @author gufg
 * @since 2025-08-05 09:44
 */
public class DropNamespace {
    public static void main(String[] args) throws IOException {
        // 连接HBase
        Connection connection = ConnectionFactory.createConnection();

        // 获取Admin实例
        Admin admin = connection.getAdmin();

        try {
            // 命名空间名称
            String namespace = "intct83_api";

            List<String> listNamespaces = Arrays.asList(admin.listNamespaces());
            if (listNamespaces.contains(namespace)) {
                // 删除namespace
                admin.deleteNamespace(namespace);
            } else {
                System.out.println("命名空间不存！");
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            // 关闭
            if (admin != null) {
                admin.close();
            }
            if (connection != null) {
                connection.close();
            }
        }
    }
}
